<template>
	<view>
		<view>
			<u-form :model="form" ref="uForm">
				<u-form-item label="用户昵称:" label-width="130"><u-input v-model="form.name" /></u-form-item>
				<u-form-item label="充值金额:"  label-width="130"><u-input v-model="paymoney" dis /></u-form-item>
				<u-form-item label="充值方式:" label-width="130">
					<view style="display: flex;flex-direction:column">
						<view style="display: flex;justify-content:space-between" v-for="(pay,i) in payment">
							<view style="display: flex;align-items: center;">
								<image :src="pay.icon" style="width: 40rpx;margin-right: 20rpx;" mode="widthFix"> </image>
								<text>
									{{pay.title}}
								</text>
							</view>
							<label style="float: right;margin-left: 20rpx;">
								<radio :value="pay.title" activeBackgroundColor="#333" :checked="pays == pay.title"  @click="checkPay(pay.title)" />
							</label>
						</view>
					</view>
				</u-form-item>	
				<u-form-item label="上传凭证:" label-width="130">
					<u-upload :action="action" v-model="fileList" @on-success="uploadSuccess"></u-upload>
				</u-form-item>
			</u-form>
			
			<view style="
					width: 50%;height: 100rpx;background: #A4ADB3;color: #fff;
					border-radius: 10rpx;display: flex;justify-content: center;align-items: center;
					margin-left: 25%;
					margin-top: 200rpx;
			"
			@click="paycreate"
			>
				提交
			</view>
		</view>
	</view>
</template>

<script>
	import request from '@/common/request.js';
	export default {
		data() {
			return {
				form: {
					name: '',
				},
				paymoney:0,
				list:[

				],
				pays:"",
				ali:require('@/static/mao/alipay.png'),
				wechat:require('@/static/mao/wechat.png'),
				payment:[
					
				],
				action: 'http://egg.aiplaygpt.com/api/common/upload',
				fileList:[]
			}
		},
		mounted() {
	
		},
		onLoad(option) {
			this.paymoney = option.money;
			this.init();
		},
		methods: {
			init(){
				let user = uni.getStorageSync('userInfo');
				if(!user){
					uni.showToast({ title:'请先登录', icon: 'none' });
					setTimeout(()=>{
						uni.navigateTo({
							url:`/pages/public/login`
						})
					},1000)
					return ;
				}
				
				let opt ={
					url: 'api/index/payment',
					method: 'get'
				}
				request.httpRequest(opt).then((res)=>{
					this.payment = res.data.data;
				})
				
			},
			navTo(url){
				uni.navigateTo({
					url
				})
				
				return;
			},
			
			checkPay(type){
				this.pays = type;
				console.log(this.pays);
			},
			uploadSuccess(e){
				console.log(e);
				let url = {
					url:e.data.url
				};
				this.fileList.push(url)
			},
			paycreate(){
				console.log(this.fileList);
				if(!this.paymoney){
					uni.showToast({ title:'金额不能为空', icon: 'none' });
					return ;
				}
				if(!this.pays)
				{
					uni.showToast({ title:'请选择支付方式', icon: 'none' });
					return ;
				}
				
				
				let opts2 = {
					url: 'api/index/paysubmit',
					method: 'post'
				};
				let value = {
					name:this.form.name,
					amount:this.paymoney,
					type:this.pays,
					image:JSON.stringify(this.fileList)
				}
								
				request.httpTokenRequest(opts2,value).then((res)=>{
					if(res.data.code == '1'){
						uni.showToast({ title:res.data.msg, icon: 'none' });
						
						setTimeout(()=>{
							uni.navigateTo({
								url:`/pages/me/rechargeLog`
							})
						},1000)
						return ;
					}else{
						uni.showToast({ title:res.data.msg, icon: 'none' });
						return ;
					}
				})
				
			}
			
			
		}
	}
</script>

<style lang="less">
	page{
		background: #fff;
		padding: 30rpx;
	}
	.active{
		background: #333 !important;
		color:#fff;
	}
	
	/deep/ .u-radio-group[data-v-dd868428]
	{
		display: flex;
	}
	/deep/ .u-radio[data-v-da6758f0]{
		display: flex;
	}
</style>